package com.mju.byc.Service;

import com.mju.byc.Bean.Book;
import com.mju.byc.Dao.BookDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

@Service
@CacheConfig(cacheNames = {"bookService"})
public class BookService {
    @Autowired
    BookDao bookDao;
    @Cacheable(value = "book",key = "#id",unless = "#result==null")
    public Book getBookById(Integer id)
    {
        return bookDao.getBookById(id);
    }
    @CachePut(value = "book",key = "#book.id")
    public Book updateBook(Book book)
    {
        return bookDao.save(book);
    }
}
